<!DOCTYPE html>
<?php
require_once("DB_Config.php");
if( isset($_POST['Search']) ){

$district=$_POST['district'];
$city=$_POST['city'];
$min_num_room=$_POST['min_num_room'];
$max_num_room=$_POST['max_num_room'];
$minfloor=$_POST['minfloor'];
$maxfloor=$_POST['maxfloor'];
$rsize=$_POST['rsize'];
$datetab=$_POST['datetab'];
$prangemin=$_POST['prangemin'];
$prangemax=$_POST['prangemax'];
$property=$_POST['property'];
$tbl_name=$_POST['purpose'];
if (isset($_POST['warehouse'])) { $warehouse = $_POST['warehouse']; } 
else { $warehouse = "0"; }
if (isset($_POST['garage'])) { $garage = $_POST['garage']; } 
else { $garage = "0"; }
if (isset($_POST['alevator'])) { $alevator = $_POST['alevator']; } 
else { $alevator = "0"; }
if (isset($_POST['video'])) { $video = $_POST['video']; } 
else { $video = "0"; }
if (isset($_POST['picture'])) { $picture = $_POST['picture']; } 
else { $picture = "0"; }
if (isset($_POST['aircon'])) { $aircon = $_POST['aircon']; } 
else { $aircon = "0"; }
}//close of if( isset($_POST['Search']) )

$url  = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] :  'https://'.$_SERVER["SERVER_NAME"];
$url .= $_SERVER["REQUEST_URI"];

$db_connect = DB_Connection::getInstance();
?>

<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<link href="css/style.css" rel='stylesheet' type='text/css' />
  <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"></script>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui.min.js"></script>
  <script type="text/javascript" src="js/jquery.package-slider.js"></script>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

<script type="text/javascript">
//case district been changed and need to change to city select
function cit() {   
    var e = document.getElementById("district");
    var dis_name = e.options[e.selectedIndex].value;
    var flag=1;  //recognaizing in data.php who called him
     $('#city').load('data.php?dis_name=' + escape(dis_name) + '&flag=' + escape(flag)) ;
}

//case number of minimum rooms been change so we need to update the max num of rooms
function min_room() {   
    var e = document.getElementById("min_num_room");
    var minroom = e.options[e.selectedIndex].value;
    var flag=2;  //recognaizing in data.php who called him
     $('#max_num_room').load('data.php?minroom=' + escape(minroom) + '&flag=' + escape(flag)) ;
}

//case number of minimum floor been change so we need to update the max num of floor
function floor_range() {   
    var e = document.getElementById("minfloor");
    var min_floor = e.options[e.selectedIndex].value;
    var flag=3;  //recognaizing in data.php who called him
     $('#maxfloor').load('data.php?min_floor=' + escape(min_floor) + '&flag=' + escape(flag)) ;
}
//fixing the appartment size to be legal
function appar_size() {
    var e = document.getElementById("rsize");
    if ( isNaN(e.value) || (e.value > 600) || (e.value < 0) ) {
        alert("invalid number, please enter numbet between 0-600");
        e.value="";
    }
}
//chaecking that the minimum price range is correct
function p_range_min() {
    var e = document.getElementById("prangemin");
    if ( isNaN(e.value) || (e.value < 99) || (e.value > 50000000) ) {
        alert("invalid price , please enter price higher then 99");
        e.value="";
    }
    else{
        var x =  e.value;
        x++;
        var e = document.getElementById("prangemax");
        e.value=x;
    }
}

$(function() {
    $( "#datetab" ).datepicker({  maxDate: "+0D" ,dateFormat: 'yy-mm-dd'});
  });

// facebook modules importing
</script>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '619553498072448',                        // App ID from the app dashboard
      channelUrl : 'channel.html', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>
<?php  if( isset($_POST['Search']) ){ ?>
  <script>
  $(function() {
    $( "#accordion" ).accordion({
      collapsible: true
    });
  });
  </script>
  
<?php }?>


<!-- script for showing the histogram -->
<script>
function histogram_fadein(){  
$('#overlay').fadeIn('slow');
$('#histogram_popupBox').fadeIn('slow');
$('#histogram_popupContent').fadeIn('slow');    
}

function histogram_fadeout(){
$('#overlay').fadeOut('slow');
$('#histogram_popupBox').fadeOut('slow');
$('#histogram_popupContent').fadeOut('slow');    
}
</script>



<title>A&A ONLINE UNIVERSITY</title>
</head>

<body>

<!-- START HEADER WRAPER-->
<div id="header-color">
  <div id="header-wrapper">

    <?php require_once("header.php"); 
        if(isset($_SESSION['myusername'])==FALSE)  { header("location:index.php");} 
        else {?> <b class="hellouser"> Hello <?php echo $_SESSION['myusername']; ?></b> <?php } ?>
  </div>
</div>

<!-- START CONTENT WRAPER-->
<div id="page-wrapper">



<!-- gray backround for the buttons -->
<div id="overlay" style="display: none;"></div>

    





<!-- 
     _______. _______      ___      .______        ______  __    __      _______   ______   .______      .___  ___. 
    /       ||   ____|    /   \     |   _  \      /      ||  |  |  |    |   ____| /  __  \  |   _  \     |   \/   | 
   |   (----`|  |__      /  ^  \    |  |_)  |    |  ,----'|  |__|  |    |  |__   |  |  |  | |  |_)  |    |  \  /  | 
    \   \    |   __|    /  /_\  \   |      /     |  |     |   __   |    |   __|  |  |  |  | |      /     |  |\/|  | 
.----)   |   |  |____  /  _____  \  |  |\  \----.|  `----.|  |  |  |    |  |     |  `--'  | |  |\  \----.|  |  |  | 
|_______/    |_______|/__/     \__\ | _| `._____| \______||__|  |__|    |__|      \______/  | _| `._____||__|  |__| 
                                                                                                                
                                                                                                                -->
<!-- search form -->
<form name="house_searching" method="post" action="search_shower.php">
    <div class="home_search">

        <tr>
            <td>
                <div>
                    <label>District</label>
                    <span class="select">
                    <select id="district" name="district" style="width: 100px;" onchange="cit()">
                        <option value="0"></option>
                        <?php
                            $q = 'SELECT DISTINCT district  FROM cities';
                            $stmt = $db_connect->db_conn->prepare($q);
                            if ($stmt->execute()){
                                 $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
                                 $i = 0; 
                                 while ($i < count($res)) {                     
                            ?>
                            <option value= "<?php  echo $res[$i]['district']; ?>" >
                                <?php  echo $res[$i]['district']; $i++; ?> 
                            </option>
                            <?php 
                                } }
                            ?>
                    </select>
                    </span>

                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>City</label>
                    <span class="select">
                        <select id ="city" name="city" style="width: 130px;" >
                            <option selected="selected" value=""></option>
                        </select>
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                 <div>
                    <label>Number of bedrooms</label>
                    <span class="select">
                        <select id ="min_num_room" name="min_num_room" style="width: 55px;" onchange="min_room()">
                            <option value= "1"   >1   </option>
                            <option value= "1.5" >1.5 </option>
                            <option value= "2"   >2   </option>
                            <option value= "2.5" >2.5 </option>
                            <option value= "3"   >3   </option>
                            <option value= "3.5" >3.5 </option>
                            <option value= "4"   >4   </option>
                            <option value= "4.5" >4.5 </option>
                            <option value= "5"   >5   </option>
                            <option value= "5.5" >5.5 </option>
                            <option value= "6"   >6   </option>
                            <option value= "6.5" >6.5 </option>
                            <option value= "7"   >7   </option>
                            <option value= "7.5" >7.5 </option>
                            <option value= "8"   >8   </option>
                            <option value= "8.5" >8.5 </option>
                            <option value= "9"   >9   </option>
                            <option value= "9.5" >9.5 </option>
                            <option value= "10"  >10  </option>
                            <option value= "10.5">10.5</option>
                            <option value= "11"  >11  </option>
                            <option value= "11.5">11.5</option>
                            <option value= "12"  >12  </option>
                        </select>
                    </span>
                    <span class="select">
                        <select id ="max_num_room" name="max_num_room" style="width: 55px;">
                            <option value="12">12</option>
                        </select>
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>Floors you seek</label>
                    <span class="select">
                        <select id ="minfloor" name="minfloor" style="width: 55px;" onchange="floor_range()">
                            <option value="0">0</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                            <option value="13">13</option>
                            <option value="14">14</option>
                            <option value="15">15</option>
                            <option value="16">16</option>
                            <option value="17">17</option>
                            <option value="18">18</option>
                            <option value="19">19</option>
                            <option value="100">20+</option>
                        </select>
                    </span>
                    <span class="select">
                        <select id ="maxfloor" name="maxfloor" style="width: 55px;">
                            <option value="100">20+</option>
                        </select>
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>M ²</label>
                    <span class="select">
                        <input type="text" name="rsize" id="rsize" value="" style="width: 25px;" onchange="appar_size()">
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>Ad Age   </label>
                    <span class="select">
                        <input type="text" name="datetab" id="datetab" value="" style="width: 65px;" >
                        </input>
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <input name="Search" type="submit" value="Search" class="button" id="search_but" />
            </td>
            <br>
            <td>
                <div>
                    <label>Price Range</label>
                    <span class="select">
                        <input type="text" name="prangemin" id="prangemin" value="99" style="width: 60px;" onchange="p_range_min()">
                    </span>
                    <span class="select">
                        <input type="text" name="prangemax" id="prangemax" value="1000000" style="width: 60px;" onchange="p_range_max()">
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>Property</label>
                    <span class="select">
                        <select id ="property" name="property" style="width: 140px;" >
                            <option value="apartment">Apartment</option>
                            <option value="studio">Studio</option>
                            <option value="penthouse">Penthouse</option>
                            <option value="basement">Basement</option>
                            <option value="apartment">Apartment</option>
                            <option value="duplex">Duplex</option>
                            <option value="triplex">Triplex</option>
                            <option value="housing_unit">Housing unit</option>
                            <option value="warehouse">Warehouse</option>
                            <option value="residential_building">Residential building</option>
                            <option value="lot">Lot</option>
                        </select>
                    </span>
                </div>
            </td>
            <div>&nbsp&nbsp&nbsp</div>
            <td>
                <div>
                    <label>Purpose</label>
                    <span class="select">
                        <select id ="purpose" name="purpose" style="width: 80px;">
                            <option selected="selected" value="renthouse">rent</option>
                            <option value="sellhouse">buy</option>
                            <option value="partnerhouse">pertners</option>
                        </select>
                    </span>
                </div>
            </td>
            <br>
            <td>
                <input type="checkbox" value="1" name="warehouse" id="warehouse" style="margin:50px 0px 0px -416px">
                <span> Warehouse &nbsp&nbsp&nbsp</span>
            </td>

            <td>
                <input type="checkbox" value="1" name="garage" id="garage" style="margin:30px 0px 0px 0px">
                <span> Garage &nbsp&nbsp&nbsp</span>
            </td>

            <td>
                <input type="checkbox" value="1" name="alevator" id="alevator" style="margin:30px 0px 0px 0px">
                <span> Elevator &nbsp&nbsp&nbsp</span>
            </td>

            <td>
                <input type="checkbox" value="1" name="video" id="video" style="margin:30px 0px 0px 0px">
                <span> Video &nbsp&nbsp&nbsp</span>
            </td>

            <td>
                <input type="checkbox" value="1" name="picture" id="picture" style="margin:30px 0px 0px 0px">
                <span> Picture &nbsp&nbsp&nbsp</span>
            </td>

            <td>
                <input type="checkbox" value="1" name="aircon" id="aircon" style="margin:30px 0px 0px 0px">
                <span> Air Conditioner &nbsp&nbsp&nbsp</span>
            </td>
        </tr>
    </div>
</form>

<!-- 
     _______. _______      ___      .______        ______  __    __     .______   .______       _______      _______.     _______. _______  _______  
    /       ||   ____|    /   \     |   _  \      /      ||  |  |  |    |   _  \  |   _  \     |   ____|    /       |    /       ||   ____||       \ 
   |   (----`|  |__      /  ^  \    |  |_)  |    |  ,----'|  |__|  |    |  |_)  | |  |_)  |    |  |__      |   (----`   |   (----`|  |__   |  .--.  |
    \   \    |   __|    /  /_\  \   |      /     |  |     |   __   |    |   ___/  |      /     |   __|      \   \        \   \    |   __|  |  |  |  |
.----)   |   |  |____  /  _____  \  |  |\  \----.|  `----.|  |  |  |    |  |      |  |\  \----.|  |____ .----)   |   .----)   |   |  |____ |  '--'  |
|_______/    |_______|/__/     \__\ | _| `._____| \______||__|  |__|    | _|      | _| `._____||_______||_______/    |_______/    |_______||_______/ 
                                                                                                                                                     
-->

<?php  if( isset($_POST['Search']) ){ ?> <!--showing the accordion result if search been pressed -->
<div id="shower-wrapper">
       <tr>                          
        <span  style="padding-top: 5px; padding-bottom: 10px; float:left; margin-left: 63px; border-top: 0px; display: block;">
            
            <span style="width:134px; float:left;">Property: </span>
            <span class="span_spc"></span>

            <span style="width:75px; float:left;">District: </span>
            <span class="span_spc"></span>

            <span style="width:120px; float:left;">City: </span>
            <span class="span_spc"></span>

            <span style="width:75px; float:left;">Price: </span>
            <span class="span_spc"></span>

            <span style="width:70px; float:left;">Room&nbsp#: </span>
            <span class="span_spc"></span>

            <span style="width:70px; float:left;">Floor&nbsp#: </span>
            <span class="span_spc"></span>

            <span style="width:90px; float:left;">Date: </span>
         

          </span>
</tr> 
        
<div id="page-content">
  <div class="subjects">
        <div style="float:right;" >
            <!-- button for showing the histogram -->
            <input type="button" value="Show Histogram" name="send" onclick="histogram_fadein()" class="head_button">
        </div>
        <div style="float:left;" >
      

<?php


if ($city == ''){
  $sql="SELECT * 
        FROM $tbl_name , users
        WHERE $tbl_name.username=users.username AND $tbl_name.district=? AND $tbl_name.num_bedrooms>=? AND $tbl_name.num_bedrooms<=?
        AND $tbl_name.floor>=? AND $tbl_name.floor<=? AND $tbl_name.square_feet>=? AND $tbl_name.bump_date>=? AND $tbl_name.price>=? AND $tbl_name.price<=?
        AND $tbl_name.property=? AND $tbl_name.warehouse=? AND $tbl_name.parking=? AND $tbl_name.air_conditioner=? AND $tbl_name.elevator=?";
  $stmt = $db_connect->db_conn->prepare($sql);
  $param=array($district, $min_num_room, $max_num_room, $minfloor, $maxfloor, $rsize, $datetab, $prangemin, $prangemax, $property, $warehouse, $garage, $aircon, $alevator);
}
else{
  $sql="SELECT * 
        FROM $tbl_name , users
        WHERE $tbl_name.username=users.username AND $tbl_name.district=? AND $tbl_name.city_name=? AND $tbl_name.num_bedrooms>=? AND $tbl_name.num_bedrooms<=?
        AND $tbl_name.floor>=? AND $tbl_name.floor<=? AND $tbl_name.square_feet>=? AND $tbl_name.bump_date>=? AND $tbl_name.price>=? AND $tbl_name.price<=?
        AND $tbl_name.property=? AND $tbl_name.warehouse=? AND $tbl_name.parking=? AND $tbl_name.air_conditioner=? AND $tbl_name.elevator=?";
  $stmt = $db_connect->db_conn->prepare($sql);
  $param=array($district, $city, $min_num_room, $max_num_room, $minfloor, $maxfloor, $rsize, $datetab, $prangemin, $prangemax, $property, $warehouse, $garage, $aircon, $alevator);
}


// if ($stmt->execute($param)){
$sql="SELECT * FROM $tbl_name ,users WHERE $tbl_name.username=users.username"; //delete
    $stmt = $db_connect->db_conn->prepare($sql); //delete
        if ($stmt->execute()){ //delete
             $row = $stmt->fetchAll(PDO::FETCH_ASSOC);

  
?>

<script>
var arr_ad_id = new Array();
var arr_longitude = new Array();
var arr_latitude = new Array();

<?php $i=0;
while ( $i < count($row) ){ ?>
    arr_longitude[<?php echo $row[$i]['ad_id'];?>] = <?php echo $row[$i]['longitude'];?> ;
    arr_latitude[<?php echo $row[$i]['ad_id'];?>] = <?php echo $row[$i]['latitude'];?> ;
<?php $i++; } ?>

// script for showing the histogram
function show_google(adid){
    var myCenter=new google.maps.LatLng(arr_longitude[adid],arr_latitude[adid]);
    var marker;
    var mapProp = { center:new google.maps.LatLng(arr_longitude[adid],arr_latitude[adid]), zoom:15, mapTypeId:google.maps.MapTypeId.ROADMAP };
    var map=new google.maps.Map(document.getElementById("div_for_map"),mapProp);  
    marker=new google.maps.Marker({ position:myCenter, animation:google.maps.Animation.BOUNCE });
    marker.setMap(map); 
    $('#overlay').fadeIn('slow');
    $('#google_popupBox').fadeIn('slow');
    $('#google_popupContent').fadeIn('slow');  
    google.maps.event.trigger(map, 'resize');
    map.setZoom( map.getZoom() ); 
    map.setCenter(marker.getPosition());
}

function google_fadeout(){
    $('#overlay').fadeOut('slow');
    $('#google_popupBox').fadeOut('slow');
    $('#google_popupContent').fadeOut('slow');    
}


</script>

<!-- 
.______       _______      _______. __    __   __      .___________.   .___________.     ___      .______    __       _______ 
|   _  \     |   ____|    /       ||  |  |  | |  |     |           |   |           |    /   \     |   _  \  |  |     |   ____|
|  |_)  |    |  |__      |   (----`|  |  |  | |  |     `---|  |----`   `---|  |----`   /  ^  \    |  |_)  | |  |     |  |__   
|      /     |   __|      \   \    |  |  |  | |  |         |  |            |  |       /  /_\  \   |   _  <  |  |     |   __|  
|  |\  \----.|  |____ .----)   |   |  `--'  | |  `----.    |  |            |  |      /  _____  \  |  |_)  | |  `----.|  |____ 
| _| `._____||_______||_______/     \______/  |_______|    |__|            |__|     /__/     \__\ |______/  |_______||_______|

 -->


    <div id="accordion">
      <?php
          $i=0;
          while ( $i < count($row) ){  ?>
            <div style="display: block;">
                <tr>                               
                  <span style="width:134px; padding-left: 7px; float:left;"><?php echo $row[$i]['property']; ?> </span>
                  <span class="span_spc"></span>
                  <span style="width:75px; float:left;"><?php echo $row[$i]['district'];?></span>
                  <span class="span_spc"></span>
                  <span style="width:120px; float:left;"><?php echo $row[$i]['city_name'];?> </span>
                  <span class="span_spc"></span>
                  <span style="width:75px; float:left;"><?php echo $row[$i]['price'];?> </span>
                  <span class="span_spc"></span>
                  <span style="width:70px; float:left;"><?php echo $row[$i]['num_bedrooms'];?> </span>
                  <span class="span_spc"></span>
                  <span style="width:70px; float:left;"><?php echo $row[$i]['floor'];?> </span>
                  <span class="span_spc"></span>
                  <span style="width:90px; float:left;"><?php echo $row[$i]['bump_date'];?> </span>
                </tr> 
            </div> 
            <div>
                      <!-- START TABLE -->
              <table dir="ltr" width="750" align="center" border="0" cellpadding="0"  cellspacing="0" bgcolor="#F1F1F1">
               <tr>
                <td class="show_header"><b class="show_text">APARTMENT PROPERTIES</b></td>
                <td class="show_header"><b class="show_text">OWNER DETAILS</b></td>
                <td class="show_header"><b class="show_text">APARTMENT PICTURE</b></td>
                </tr>               
              </table>
              <table dir="ltr" width="750" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#F1F1F1">
                <td width="242" valign="top">                   
                    <!-- APARTMENT PICTURE -->
                    <table class="table_show" width="242" border="0" align="right" cellpadding="0" cellspacing="0">
                      <tr>
                        <td colspan="3"><b><img src="http://www.bluebayinn.com/images/ExecutiveApartment.jpg" width="237" height="150" border="0" alt=""></b></td>  
                      </tr>
                    </table>
                     <!-- OWNER DETAILS -->
                    <table width="242" border="0" align="right" cellpadding="0" cellspacing="0">
                        <tr>       
                            <td width="65" style="padding-right: 10px">Name:</td>
                            <td colspan="3"><b><?php echo $row[$i]['username']; ?></b></td>
                        </tr>
                        <tr>       
                            <td width="65" style="padding-right: 10px">Phone:</td>
                            <td colspan="3"><b><?php echo $row[$i]['last_name']; ?></b></td>
                        </tr>
                        <tr>       
                            <td width="65" style="padding-right: 10px">Email:</td>
                            <td colspan="3"><b><?php echo $row[$i]['email']; ?></b></td>
                        </tr>
                        <tr>
                            <td>
                                <!-- facebook -->
                               <div class="fb-like" data-href="http://chinatown.co.il" data-width="65" data-layout="button_count" data-show-faces="true" data-send="true"></div>
                           </td>
                        </tr>                          
                    </table>

                    <!-- APARTMENT PROPERTIES -->
                    <table width="245" border="0" align="right" cellpadding="0" cellspacing="0">
                      <tr>        
                                <td width="65" style="padding-right: 10px">Property:</td>
                                <td colspan="3"><b><?php echo $row[$i]['property']; ?></b></td>
                      </tr>               
                      <tr>
                                <td width="65" style="padding-right: 10px">District:</td>
                                <td colspan="3"><b><?php echo $row[$i]['district']; ?></b></td>
                            </tr>
                      <tr>
                        <td width="63" style="padding-right: 10px">City:</td>
                        <td colspan="3"><b><?php echo $row[$i]['city_name']; ?></b></td>
                      </tr>
                      <tr>
                        <td width="63" style="padding-right: 10px">Address:</td>
                        <td colspan="3"><b><?php echo $row[$i]['address']; ?></b></td>
                      </tr>           
                       <tr>
                        <td width="65" style="padding-right: 10px">Room #:</td>
                        <td colspan="3"><b><?php echo $row[$i]['num_bedrooms']; ?></b></td>
                      </tr>
                      <tr>
                        <td width="65" style="padding-right: 10px">Floor #:</td>            
                        <td colspan="3"><b><?php echo $row[$i]['floor']; ?></b></td>
                      </tr>
                      <tr>
                        <td width="69" style="padding-right: 10px">Square&nbspFoot:</td>            
                        <td colspan="3"><b><?php echo $row[$i]['square_feet']; ?></b></td>
                      </tr>
                      <tr>
                        <td width="69" style="padding-right: 10px">Price:</td>            
                        <td colspan="3"><b><?php echo $row[$i]['price']; ?></b></td>
                      </tr>
                    </table>
                  </td>
                </table>
                <!--END ROW -->

                <table dir="ltr" width="750" height="13" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#F1F1F1">
                </table>

                <!-- START TABLE -->
              <table dir="ltr" width="750" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#F1F1F1">
               <tr>
                <td class="show_header"><b class="show_text">APARTMENT FEATURES</b></td>
                <td class="show_header"><b class="show_text">Google Maps</b></td>
                <td class="show_header"><b class="show_text">APARTMENT VIDEO</b></td>
                </tr>
                
              </table>
                <table dir="ltr" width="750" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="#F1F1F1">
                  <td width="242" valign="top">
                    <!-- APARTMENT Video -->
                    <table class="table_show" width="242" border="0" align="right" cellpadding="0" cellspacing="0">

                    <tr>
                    <td colspan="3">
                    <iframe width="237" height="160" src="data.php?y_tube_id=<?php echo $row[$i]['video'];?>" frameborder="0" allowfullscreen></iframe>

                    </td> 
                    </tr>
                </table>
                  <!-- Google Maps -->
                  <table class="table_show" width="242" border="0" align="right" cellpadding="0" cellspacing="0">

                  <tr>
                  <td colspan="3">
                    <b>
                        <div id=<?php echo $row[$i]['ad_id'];?> style="width:220px;height:150px;">
                            <!-- button for showing the histogram -->
                            <input style="background-color: rgb(255, 143, 0); width: 214px; height: 34px;" type="button" value="Show The Place On The Map" name="send1" onclick="show_google(<?php echo $row[$i]['ad_id'];?>)" class="head_button">
                            <!-- <button onclick="show_google(<?php echo $row[$i]['ad_id'];?>)">xxxxx</button> -->
                        </div>
                    </b>
                  </td> 
                  </tr>
                  </table>
                  <!-- APARTMENT FEATURES -->
                <table  class="table_show_features" width="242" border="0" align="right" cellpadding="0" cellspacing="0">
                  <tr>
                    <tr>      
                              <td width="65" style="padding-right: 10px">Enterance&nbspDate:</td>
                              <td colspan="3"><b><?php echo $row[$i]['entrance_date']; ?></b></td>
                          </tr>
                          <!--  <img src="images/vi.gif" width="14" height="13" border="0" alt="">
                              <img src="images/x.gif" width="14" height="13" border="0" alt=""> -->
                          <tr>      
                              <td width="65" style="padding-right: 10px">Warehouse:</td>
                              <td colspan="3"><b><?php echo $row[$i]['warehouse']; ?></b></td>
                          </tr>
                          <tr>      
                              <td width="65" style="padding-right: 10px">Parking:</td>
                              <td colspan="3"><b><?php echo $row[$i]['parking']; ?></b></td>
                          </tr>
                          <tr>      
                              <td width="65" style="padding-right: 10px">Air&nbspConditioner:</td>
                              <td colspan="3"><b><?php echo $row[$i]['air_conditioner']; ?></b></td>
                          </tr>
                          <tr>      
                              <td width="65" style="padding-right: 10px">Elevator:</td>
                              <td colspan="3"><b><?php echo $row[$i]['elevator']; ?></b></td>
                          </tr>
                          <tr>      
                              <td width="65" style="padding-right: 10px">Comments:</td>
                              <td colspan="3"><b><?php echo $row[$i]['comments']; ?></b></td>
                          </tr>
                      </tr>
                </table>
                    
                </td>
              </table>
                <!--END ROW -->
            </div>
       <?php   

            //calculation for histogram:
            $arr[$i] = $row[$i]['price'];




              $i++;   }  // while loop
                 } //$stmt->execute()


 
                                                                                                             
 








                 ?>
</div>
</div>


<!-- END CONTENT WRAPER-->
<br>

</div>
</div>
</div><!-- END shower-->
<?php }?>
</div><!-- END page-wrapper-->
<!-- START FOOTER WRAPER-->
<p><?php require("footer.php"); ?></p>
</body>
</html>


<!-- 
  _______   ______     ______     _______  __       _______    .___  ___.      ___      .______   
 /  _____| /  __  \   /  __  \   /  _____||  |     |   ____|   |   \/   |     /   \     |   _  \  
|  |  __  |  |  |  | |  |  |  | |  |  __  |  |     |  |__      |  \  /  |    /  ^  \    |  |_)  | 
|  | |_ | |  |  |  | |  |  |  | |  | |_ | |  |     |   __|     |  |\/|  |   /  /_\  \   |   ___/  
|  |__| | |  `--'  | |  `--'  | |  |__| | |  `----.|  |____    |  |  |  |  /  _____  \  |  |      
 \______|  \______/   \______/   \______| |_______||_______|   |__|  |__| /__/     \__\ | _|    
  -->

<div id="google_popupBox" style="display: none;">     
    <div id="google_popupContent" style="display: none;"><i>Google Map Of The Area:</i><br>      
        <br>
        <div id="div_for_map" style="width: 900; height: 400px; background-color: rgb(120, 158, 19);">
        </div>
        <button class="head_button" onclick="google_fadeout()" style="float: right;">Close</button><br>      
    </div>
</div>

<?php
//  __    __   __       _______..___________..______        ______     _______ .______           ___      .___  ___. 
// |  |  |  | |  |     /       ||           ||   _  \      /  __  \   /  _____||   _  \         /   \     |   \/   | 
// |  |__|  | |  |    |   (----``---|  |----`|  |_)  |    |  |  |  | |  |  __  |  |_)  |       /  ^  \    |  \  /  | 
// |   __   | |  |     \   \        |  |     |      /     |  |  |  | |  | |_ | |      /       /  /_\  \   |  |\/|  | 
// |  |  |  | |  | .----)   |       |  |     |  |\  \----.|  `--'  | |  |__| | |  |\  \----. /  _____  \  |  |  |  | 
// |__|  |__| |__| |_______/        |__|     | _| `._____| \______/   \______| | _| `._____|/__/     \__\ |__|  |__| 
?>


    <div id="histogram_popupBox" style="display: none;">     
        <div id="histogram_popupContent" style="display: none;"><i>Histogram that matches to you search :</i><button class="head_button" onclick="histogram_fadeout()" style="float: right;">Close</button><br>      
            <br>
            
            <?php
            $min = $arr[0];
            $max = $arr[0];
            for ($a = 0; $a < $i; $a++) {
                if ( $min > $arr[$a] ) { $min = $arr[$a];}
                if ( $max < $arr[$a] ) { $max = $arr[$a];}                                   
                // echo $arr[$a]."\n";
            }
            // echo "min: ".$min."\n";
            // echo "max: ".$max."\n";
            $mid = ($max-$min)/10;
            // echo "mid: ".$mid."\n";

            $uptoprice = $min + $mid;
            $sum = 0;
            for ($a = 0; $a < 10; $a++) {
                $counter = 0;
                
                for ($b = 0; $b < $i; $b++) {
                    if ( (($uptoprice+1) > $arr[$b]) && ( ($uptoprice-$mid-1) < $arr[$b]) ) { $counter++; $sum++; }
                }
                $histogram_arr["up to ".$uptoprice] = $counter;
                $uptoprice = $uptoprice + $mid;
            }
            // $max = max($histogram_arr);
            $max = $sum;
            echo '<table>';
            echo '<tr>';
            foreach ($histogram_arr as $k=>$v)
            {
                echo "<td>&nbsp".$v."</td>";
                echo "<td> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp     </td>";
            }
            echo '</tr>';

            echo '<tr>';
            foreach ($histogram_arr as $k=>$v)
            {
                echo "<td><img src='bar.php?max=$max&val=$v'></td>";
                echo "<td>   &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp   </td>";
            }
            echo '</tr>';

            echo '<tr>';
            foreach ($histogram_arr as $k=>$v)
            {
                echo "<td>$k</td>";
                echo "<td>   &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp   </td>";
            }
            echo '</tr>';
            ?>
            

        </div>
    </div>


